#!/bin/bash

#编译动态连接库
clear

cd lib_core
rm -rf build
mkdir build

rm -rf lib_custom_drv_pwm
mkdir lib_custom_drv_pwm
mkdir lib_custom_drv_pwm/include
mkdir lib_custom_drv_pwm/lib

cd build

cmake ../
make -j8

# 检查编译是否成功
LIB_PATH="libcustom_drv_pwm.so"

if [ -f "$LIB_PATH" ]; then
	echo "动态库已生成"
else
	echo "未找到动态库文件！"
	exit 1
fi

#拷贝动态连接库
cd ..
rm -rf lib_custom_drv_pwm
mkdir lib_custom_drv_pwm

mkdir lib_custom_drv_pwm/lib
cp build/lib* lib_custom_drv_pwm/lib/.

mkdir lib_custom_drv_pwm/include
cp ./*.h lib_custom_drv_pwm/include/.

cd ..
mkdir lib
rm -rf lib/lib_custom_drv_pwm
mv lib_core/lib_custom_drv_pwm ./lib

#编译demo
# clear

rm -rf build
mkdir build
cd build

cmake ../
make -j8

cd ..

#生成运行环境
rm -rf run_pwm_demo
mkdir run_pwm_demo
cp build/PWM_DEMO run_pwm_demo/.
cp lib/lib_custom_drv_pwm run_pwm_demo/. -rf
cp run_demo.sh run_pwm_demo/.

cp run_pwm_demo ~/Public/. -rf

echo "cmake ARM 架构 生成运行环境"
